package com.amumu.drama.common.config.redis;

import cn.hutool.core.util.StrUtil;
import com.google.common.collect.Maps;
import lombok.Getter;

import java.util.Arrays;
import java.util.Map;

/**
 * Created by freethinker on 2022-02-14.
 */
@Getter
public enum AppRateLimitType {
    /**
     * 限流key
     */
    ORDER("order", "创建订单"),
    ;

    private static final Map<String, AppRateLimitType> LOOKUP = Maps.uniqueIndex(
            Arrays.asList(AppRateLimitType.values()),
            AppRateLimitType::getName
    );

    private final String name;
    private final String desc;

    AppRateLimitType(String name, String desc) {
        this.name = name;
        this.desc = desc;
    }

    /** 根据数值转换枚举 */
    public static AppRateLimitType parse(String name) {
        if (StrUtil.isBlank(name)) {
            return null;
        }
        return LOOKUP.get(name);
    }

}
